// pages/learningsituationreport/learningsituationreport.js
import * as echarts from '../../ec-canvas/echarts';
import http from '../../utils/requestAnalysis'
let chart = null;
function setTrendOption(chart, xAxis, series) {
    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            confine: true
        },
        toolbox: {
            show: false
        },
        xAxis: {
            type: 'category',
            data: xAxis,
            show: true,
            axisLabel: { // 坐标轴刻度标签
                show: true,
                rotate: 45,
            },
            axisTick: { // 坐标轴刻度
                show: true
            },
            axisLine: { // 坐标轴线
                show: true
            }
        },
        grid: {
            bottom: '30%'  // 为旋转的标签留出足够空间
        },
        yAxis: {
            type: 'value',
            axisLabel: { // 坐标轴刻度标签
                show: true,
                color: '#333',
                textStyle: {
                    fontSize: 12
                }
            },
            axisTick: { // 坐标轴刻度
                show: true
            },
            axisLine: { // 坐标轴线
                show: true
            }
        },
        legend: {
            show: true
        },
        series: series
    };
    chart.setOption(option);
}
function setTrendOptions(chart, series) {
    const option = {
        radar: {
            // shape: 'circle',
            indicator: [
                { name: '语文', max: 6500 },
                { name: '数学', max: 16000 },
                { name: '英语', max: 30000 },
                { name: '物理', max: 38000 },
                { name: '化学', max: 52000 },
                { name: '生物', max: 25000 }
            ]
        },
        toolbox: {
            show: false
        },
        legend: {
            show: true,
            bottom: 0
        },
        series: series
    };
    chart.setOption(option);
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        selectMenu: {},
        height: null,
        ec: {
            lazyLoad: true
        },
        ecs: {
            lazyLoad: true
        },
        assignedPoints: false,
        modelfftype: null,
        questionList: [],
        examinationInfo: {},
        questionDifficultyAnalyse: [],
        showLong: true,
        level1: 1,
        level2: 1,
        major: false,
        xData: ['150', '140', '130', '120', '110'],
        yData: [
            150, 140, 130, 120, 110
        ],
        examObj: {},
        errorQuestions: {},
        schoolObj: {},
        classObj: {},
        menuList: [],
        menuListS: [],
        scoreList: [],
        scoring: false,
        grading: [
            {
                grading: 'A',
                proportion: '15%',
                ratio: '0-15%',
                interval: '100-86'
            },
            {
                grading: 'B',
                proportion: '35%',
                ratio: '16%-50%',
                interval: '85-71'
            },
            {
                grading: 'C',
                proportion: '35%',
                ratio: '51%-85%',
                interval: '70-56'
            },
            {
                grading: 'D',
                proportion: '13%',
                ratio: '86%-98%',
                interval: '55-41'
            },
            {
                grading: 'E',
                proportion: '2%',
                ratio: '99%-100%',
                interval: '40-30'
            }
        ]
    },
    // changeMenu(e) {
    //     //console.log(e.detail, 'sssssssssssssssss');
    //     if (e.detail.examSubjectName == '语文' || e.detail.examSubjectName == '数学' || e.detail.examSubjectName == '英语' || e.detail.examSubjectName == '日语' || e.detail.examSubjectName == '物理' || e.detail.examSubjectName == '历史') {
    //         this.setData({
    //             major: true
    //         })
    //         if (this.data.assignedPoints) {
    //             this.setData({
    //                 assignedPoints: false
    //             })
    //             this.getScoreInfo()
    //         }
    //     } else {
    //         this.setData({
    //             major: false
    //         })
    //     }

    //     this.setData({
    //         selectMenu: e.detail
    //     })
    //     wx.setStorageSync('selectMenu', JSON.stringify(e.detail));
    //     if (this.data.selectMenu.examSubjectName.indexOf('总分') == -1) {
    //         this.getSubjectScoreInfo()
    //         this.getScoreSegmentDistribution()
    //         this.getQuestionAnalyse()
    //         this.getQuestionDifficultyAnalyse()
    //         this.getStuCard()
    //     } else {
    //         this.setData({
    //             examObj: {
    //                 examRankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2),
    //                 examERankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2)
    //             },
    //             schoolObj: {
    //                 schoolRankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2),
    //                 schoolERankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2)
    //             },
    //             classObj: {
    //                 classRankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2),
    //                 classERankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2)
    //             }
    //         })
    //     }
    // },
    changeMenu(e) {
        const { endowFlag } = e.detail;

        console.log(e.detail, 'sssssssssssssssss');

        // 根据科目名称设置 major（原逻辑不变）
        if (
            e.detail.examSubjectName == '语文' ||
            e.detail.examSubjectName == '数学' ||
            e.detail.examSubjectName == '英语' ||
            e.detail.examSubjectName == '日语' ||
            e.detail.examSubjectName == '物理' ||
            e.detail.examSubjectName == '历史'
        ) {
            this.setData({ major: true });
        } else {
            this.setData({ major: false });
        }

        // 根据 endowFlag 自动切换原始分或赋分
        this.setData({
            assignedPoints: endowFlag === 1
        });

        // 保存当前选中科目
        this.setData({ selectMenu: e.detail });
        wx.setStorageSync('selectMenu', JSON.stringify(e.detail));

        // 重新请求数据
        this.getScoreInfo();

        if (this.data.selectMenu.examSubjectName.indexOf('总分') === -1) {
            this.getSubjectScoreInfo();
            this.getScoreSegmentDistribution();
            this.getQuestionAnalyse();
            this.getQuestionDifficultyAnalyse();
            this.getStuCard();
        } else {
            this.setData({
                examObj: {
                    examRankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2),
                    examERankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2)
                },
                schoolObj: {
                    schoolRankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2),
                    schoolERankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2)
                },
                classObj: {
                    classRankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2),
                    classERankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2)
                }
            });
        }
    },

    changeShowLong(e) {
        this.setData({
            showLong: e.currentTarget.dataset.index
        })
    },
    // changeAssignedPoints(e) {
    //     this.setData({
    //         assignedPoints: e.currentTarget.dataset.id
    //     })
    //     this.getScoreInfo()
    // },
    changelevel(e) {
        this.setData({
            level1: e.currentTarget.dataset.index
        })
    },
    changelevels(e) {
        this.setData({
            level2: e.currentTarget.dataset.index
        })
    },
    getTrend() {
        setTimeout(() => {
            let this_ = this
            // 初始化完成之后，直接获取后台数据进行绘制canvas
            this.ecDataTrendComponent.init((canvas, width, height, dpr) => {
                // 获取组件的 canvas、width、height 后的回调函数
                // 在这里初始化图表
                const chart = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: dpr // new
                });
                // let xAxis = {
                //   type: 'category',
                //   data: this.data.xdata
                // }
                let xAxis = this.data.xData
                let arr = [{
                    type: 'bar',
                    data: this.data.yData,
                    itemStyle: {
                        // color: '#9FE0AD',
                        color: function (params) {
                            const value = this_.data.yData[params.dataIndex];
                            if (value === Math.max(...this_.data.yData)) {
                                return '#C96B5D'; // 最大值颜色
                            } else {
                                return '#9FE0AD'; // 其他值颜色
                            }
                        }
                    },
                    label: {
                        show: true,
                        position: 'top',
                        color: '#2c3e50'
                    },
                    // emphasis: {
                    //     itemStyle: {
                    //         color: '#D4F0E4',
                    //         shadowBlur: 10,
                    //         shadowColor: 'rgba(0, 0, 0, 0.5)'
                    //     }
                    // }
                }]
                let series = arr
                console.log(xAxis, series, '-------------------------');
                // 将后台的值传递给 setTrendOption 方法
                setTrendOption(chart, xAxis, series);
                // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
                this.ecDataTrendChart = chart;
                // 注意这里一定要返回 chart 实例，否则会影响事件处理等
                return chart;
            });
        }, 100)
    },
    getTrends() {
        setTimeout(() => {
            // 初始化完成之后，直接获取后台数据进行绘制canvas
            this.ecDataTrendComponents.init((canvas, width, height, dpr) => {
                // 获取组件的 canvas、width、height 后的回调函数
                // 在这里初始化图表
                const chart = echarts.init(canvas, null, {
                    width: width,
                    height: height,
                    devicePixelRatio: dpr // new
                });
                // let xAxis = {
                //   type: 'category',
                //   data: this.data.xdata
                // }
                // let xAxis = this.data.xData
                let arr = [
                    {
                        type: 'radar',
                        data: [
                            {
                                value: [4200, 3000, 20000, 35000, 50000, 18000],
                                name: '总分击败率'
                            },
                            {
                                value: [5000, 14000, 28000, 26000, 42000, 21000],
                                name: '科目击败率'
                            }
                        ]
                    }
                ]
                let series = arr
                // 将后台的值传递给 setTrendOption 方法
                setTrendOptions(chart, series);
                // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
                this.ecDataTrendChart = chart;
                // 注意这里一定要返回 chart 实例，否则会影响事件处理等
                return chart;
            });
        }, 0)
    },
    async getMenuLists() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            //   let id = JSON.parse(wx.getStorageSync('token')).id
            let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let datas = JSON.parse(wx.getStorageSync('studentToken'))
            let stuNameOrExamNo = null
            if (datas) {
                stuNameOrExamNo = datas.examNumber
            }
            let options = {
                url: '/analysis/subject/get',
                method: 'POST',
                data: {
                    navId: id,
                    stuNameOrExamNo: stuNameOrExamNo
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            //console.info(res)
            if (res.data.code == 0) {
                // if(res.data.obj.info=='考试已结束'){
                //     this.setData({endstartlist:''})
                //     return false
                // }
                // this.setData({endstartlist:res.data.data})
                this.setData({ menuList: res.data.data, selectMenu: res.data.data[0] })
                this.getAchievement()
                //console.log(res.data, 'vvvvvvvvvvvvv')
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            //   wx.redirectTo({
            //     url: '/pages/newstudentlogin/newstudentlogin',
            //   })
        }
    },
    async getAchievement() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
            let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let options = {
                url: '/analysis/stu/score/get',
                method: 'POST',
                data: {
                    navId: this.data.selectMenu.navId,
                    stuId: stuId,
                    pid: id
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            if (res.data.code == 0) {
                this.setData({ scoreList: res.data.data })
                //console.log(res.data, 'vvvvvvvvvvvvv')
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            //   wx.redirectTo({
            //     url: '/pages/newstudentlogin/newstudentlogin',
            //   })
        }
    },
    async getToken() {
        let that = this
        // if(wx.getStorageSync('studentToken')){
        // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
        // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
        let options = {
            url: '/login',
            method: 'POST',
            data: {
                username: 19963798837,
                password: 798837,
            },
            header: { "content-type": "application/json;charset=UTF-8" }
        }
        let res = await http(options)
        if (res.data.code == 200) {
            let token = JSON.stringify(res.data.token)
            wx.setStorageSync('studentToken', token)
            //console.log(res.data, 'vvvvvvvvvvvvv')
        } else {
            wx.showToast({
                title: res.data.msg,
                icon: 'success',
                duration: 2000 //持续的时间
            })
        }
        // }else{
        //   wx.redirectTo({
        //     url: '/pages/newstudentlogin/newstudentlogin',
        //   })
        // }
    },
    // async getScoreInfo() {
    //     let that = this
    //     if (wx.getStorageSync('studentToken')) {
    //         // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
    //         // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
    //         let options = {
    //             url: '/analysis/score/scoreInfo',
    //             method: 'GET',
    //             data: {
    //                 examId: this.data.examinationInfo.id,
    //                 endowFlag: this.data.assignedPoints ? 1 : 0
    //             },
    //             header: { "content-type": "application/json;charset=UTF-8" }
    //         }
    //         let res = await http(options)
    //         if (res.data.code == 200) {
    //             if (wx.getStorageSync('selectMenu')) {
    //                 this.setData({ menuList: res.data.data })
    //                 let selectMenu = JSON.parse(wx.getStorageSync('selectMenu'))
    //                 let arr = res.data.data.filter(item => {
    //                     return item.examSubjectId === selectMenu.examSubjectId
    //                 })
    //                 if (arr.length > 0) {
    //                     this.setData({ selectMenu: arr[0] })
    //                     wx.setStorageSync('selectMenu', JSON.stringify(arr[0]));
    //                 } else {
    //                     this.setData({ selectMenu: res.data.data[0] })
    //                     wx.setStorageSync('selectMenu', JSON.stringify(res.data.data[0]));
    //                 }
    //             } else {
    //                 this.setData({ menuList: res.data.data, selectMenu: res.data.data[0] })
    //                 wx.setStorageSync('selectMenu', JSON.stringify(res.data.data[0]));
    //             }
    //             if (this.data.selectMenu.examSubjectName.indexOf('总分') == -1) {
    //                 this.getSubjectScoreInfo()
    //                 this.getScoreSegmentDistribution()
    //                 this.getQuestionAnalyse()
    //                 this.getQuestionDifficultyAnalyse()
    //                 this.getStuCard()
    //             } else {
    //                 this.setData({
    //                     examObj: {
    //                         examRankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2),
    //                         examERankbaifen: (((this.data.selectMenu.examStudentCount - this.data.selectMenu.examRank) / this.data.selectMenu.examStudentCount) * 100).toFixed(2)
    //                     },
    //                     schoolObj: {
    //                         schoolRankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2),
    //                         schoolERankbaifen: (((this.data.selectMenu.schoolStudentCount - this.data.selectMenu.schoolRank) / this.data.selectMenu.schoolStudentCount) * 100).toFixed(2)
    //                     },
    //                     classObj: {
    //                         classRankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2),
    //                         classERankbaifen: (((this.data.selectMenu.classStudentCount - this.data.selectMenu.classRank) / this.data.selectMenu.classStudentCount) * 100).toFixed(2)
    //                     }
    //                 })
    //             }
    //         } else {
    //             wx.showToast({
    //                 title: res.data.msg,
    //                 icon: 'success',
    //                 duration: 2000 //持续的时间
    //             })
    //         }
    //     } else {
    //         wx.redirectTo({
    //             url: '/pages/newstudentlogin/newstudentlogin',
    //         })
    //     }
    // },
    async getScoreInfo() {
        if (!wx.getStorageSync('studentToken')) {
            wx.redirectTo({ url: '/pages/newstudentlogin/newstudentlogin' })
            return
        }

        let options = {
            url: '/analysis/score/scoreInfo',
            method: 'GET',
            data: {
                examId: this.data.examinationInfo.id,
                endowFlag: this.data.assignedPoints ? 1 : 0
            },
            header: { "content-type": "application/json;charset=UTF-8" }
        }

        let res = await http(options)

        if (res.data.code === 200) {
            const rawMenuList = res.data.data || []
            // ✅ 保存原始数据，方便切换赋分时重新过滤
            this.setData({ rawMenuList })

            // ✅ 按 endowFlag 过滤
            const filteredMenu = this.data.assignedPoints
                ? rawMenuList
                : rawMenuList.filter(item => item.endowFlag === 0)

            this.setData({ menuListS: filteredMenu,menuList: res.data.data })

            // ✅ 处理当前选中的科目
            const savedSelectMenu = wx.getStorageSync('selectMenu')
                ? JSON.parse(wx.getStorageSync('selectMenu'))
                : null

            let currentSelect = null

            if (savedSelectMenu) {
                // endowFlag 也要匹配，防止“地理”误匹配“地理(赋分)”
                currentSelect = filteredMenu.find(
                    item => item.examSubjectId === savedSelectMenu.examSubjectId &&
                        item.endowFlag === savedSelectMenu.endowFlag
                )
            }

            if (!currentSelect && filteredMenu.length > 0) {
                currentSelect = filteredMenu[0]
            }

            if (currentSelect) {
                this.setData({ selectMenu: currentSelect })
                wx.setStorageSync('selectMenu', JSON.stringify(currentSelect))
            }

            // ✅ 调用后续的分析接口
            if (this.data.selectMenu.examSubjectName.indexOf('总分') === -1) {
                this.getSubjectScoreInfo()
                this.getScoreSegmentDistribution()
                this.getQuestionAnalyse()
                this.getQuestionDifficultyAnalyse()
                this.getStuCard()
            } else {
                const s = this.data.selectMenu
                this.setData({
                    examObj: {
                        examRankbaifen: (((s.examStudentCount - s.examRank) / s.examStudentCount) * 100).toFixed(2),
                        examERankbaifen: (((s.examStudentCount - s.examRank) / s.examStudentCount) * 100).toFixed(2)
                    },
                    schoolObj: {
                        schoolRankbaifen: (((s.schoolStudentCount - s.schoolRank) / s.schoolStudentCount) * 100).toFixed(2),
                        schoolERankbaifen: (((s.schoolStudentCount - s.schoolRank) / s.schoolStudentCount) * 100).toFixed(2)
                    },
                    classObj: {
                        classRankbaifen: (((s.classStudentCount - s.classRank) / s.classStudentCount) * 100).toFixed(2),
                        classERankbaifen: (((s.classStudentCount - s.classRank) / s.classStudentCount) * 100).toFixed(2)
                    }
                })
            }
        } else {
            wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
            })
        }
    },

    async getSubjectScoreInfo() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
            // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let options = {
                url: '/analysis/score/subjectScoreInfo',
                method: 'GET',
                data: {
                    examId: this.data.examinationInfo.id,
                    subjectId: this.data.selectMenu.examSubjectId,
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            if (res.data.code == 200) {
                // this.setData({menuList: res.data.data,selectMenu: res.data.data[0]})
                // 计算联考的最高分平均分
                let examObj = {
                    maxScore: null,
                    maxEscore: null,
                    avgScore: null,
                    avgEscore: null,
                }
                let schoolObj = {
                    maxScore: null,
                    maxEscore: null,
                    avgScore: null,
                    avgEscore: null,
                }
                let classObj = {
                    maxScore: null,
                    maxEscore: null,
                    avgScore: null,
                    avgEscore: null,
                }
                if (res.data.data['1']) {
                    res.data.data['1'].map(item => {
                        if (item.endowFlag == 0) {
                            examObj.maxScore = item.highScore
                            examObj.avgScore = item.avgScore
                            examObj.examRank = item.examRank
                            examObj.examRankbaifen = (((item.studentCount - item.examRank) / item.studentCount) * 100).toFixed(2)
                        } else {
                            examObj.maxEscore = item.highScore
                            examObj.avgEscore = item.avgScore
                            examObj.examERank = item.examRank
                            examObj.examERankbaifen = (((item.studentCount - item.examRank) / item.studentCount) * 100).toFixed(2)
                        }
                    })
                }
                if (res.data.data['2']) {
                    res.data.data['2'].map(item => {
                        if (item.endowFlag == 0) {
                            schoolObj.maxScore = item.highScore
                            schoolObj.avgScore = item.avgScore
                            schoolObj.schoolRank = item.schoolRank
                            schoolObj.schoolRankbaifen = (((item.studentCount - item.schoolRank) / item.studentCount) * 100).toFixed(2)
                        } else {
                            schoolObj.maxEscore = item.highScore
                            schoolObj.avgEscore = item.avgScore
                            schoolObj.schoolERank = item.schoolRank
                            schoolObj.schoolERankbaifen = (((item.studentCount - item.schoolRank) / item.studentCount) * 100).toFixed(2)
                        }
                    })
                }
                if (res.data.data['3']) {
                    res.data.data['3'].map(item => {
                        if (item.endowFlag == 0) {
                            classObj.maxScore = item.highScore
                            classObj.avgScore = item.avgScore
                            classObj.classRank = item.classRank
                            classObj.classRankbaifen = (((item.studentCount - item.classRank) / item.studentCount) * 100).toFixed(2)
                        } else {
                            classObj.maxEscore = item.highScore
                            classObj.avgEscore = item.avgScore
                            classObj.classERank = item.classRank
                            classObj.classERankbaifen = (((item.studentCount - item.classRank) / item.studentCount) * 100).toFixed(2)
                        }
                    })
                }
                this.setData({
                    examObj: examObj,
                    schoolObj: schoolObj,
                    classObj: classObj
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newstudentlogin/newstudentlogin',
            })
        }
    },
    async getScoreSegmentDistribution() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
            // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let options = {
                url: '/analysis/total/score/student/scoreSegmentDistribution',
                method: 'GET',
                data: {
                    examId: this.data.examinationInfo.id,
                    subjectId: this.data.selectMenu.examSubjectId,
                    endowFlag: this.data.assignedPoints ? 1 : 0,//是否赋分1,0
                    segmentInterval: 20,//几分一段
                    scoreType: '1',//1单学科，2总分
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            if (res.data.code == 200) {
                // this.setData({menuList: res.data.data,selectMenu: res.data.data[0]})
                let xData = []
                let yData = []
                res.data.data.map(ress => {
                    xData.push(ress.segmentInfo)
                    yData.push(ress.sameScoreNumber)
                })
                this.setData({
                    xData: xData,
                    yData: yData
                })
                console.log(xData, yData, '****************')
                this.ecDataTrendComponent = this.selectComponent('#mychart-dom-lines');
                this.getTrend()
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newstudentlogin/newstudentlogin',
            })
        }
    },
    async getQuestionAnalyse() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
            // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let options = {
                url: '/analysis/question/questionAnalyse',
                method: 'GET',
                data: {
                    examId: this.data.examinationInfo.id,
                    subjectId: this.data.selectMenu.examSubjectId,
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            if (res.data.code == 200) {
                this.setData({ questionList: res.data.data, duanQuestionList: res.data.data.slice(0, 6) })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newstudentlogin/newstudentlogin',
            })
        }
    },
    // async getQuestionDifficultyAnalyse() {
    //     let that = this
    //     if(wx.getStorageSync('studentToken')){
    //         // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
    //         // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
    //         let options={
    //             url:'/analysis/question/questionDifficultyAnalyse',
    //             method:'GET',
    //             data:{
    //                 examId: this.data.examinationInfo.id,
    //                 subjectId: this.data.selectMenu.examSubjectId,
    //             },
    //             header:{"content-type":"application/json;charset=UTF-8"}
    //         }
    //         let res = await http(options)
    //         if(res.data.code==200){
    //             this.setData({
    //                 questionDifficultyAnalyse: res.data.data
    //             })
    //             let errorQuestions = {}
    //             res.data.data.map(ress => {
    //                 errorQuestions[ress.difficultyName] = ress.errorQuestions
    //             })
    //             this.setData({
    //                 errorQuestions: errorQuestions
    //             })
    //         }else{
    //             wx.showToast({
    //             title: res.data.msg,
    //             icon: 'success',
    //             duration: 2000 //持续的时间
    //             })
    //         }
    //     }else{
    //       wx.redirectTo({
    //         url: '/pages/newstudentlogin/newstudentlogin',
    //       })
    //     }
    // },
    async getQuestionDifficultyAnalyse() {
        let that = this;
        if (wx.getStorageSync('studentToken')) {
            let options = {
                url: '/analysis/question/questionDifficultyAnalyse',
                method: 'GET',
                data: {
                    examId: this.data.examinationInfo.id,
                    subjectId: this.data.selectMenu.examSubjectId,
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            };
            let res = await http(options);
            if (res.data.code == 200) {
                let list = res.data.data || [];

                list.forEach(item => {
                    item.rightRateFormatted = (item.rightRate * 100).toFixed(2); // 转为百分比并保留两位小数
                    item.questionNumberRateFormatted = (item.questionNumberRate * 100).toFixed(2);
                });

                // 处理 errorQuestions
                let errorQuestions = {};
                list.forEach(ress => {
                    errorQuestions[ress.difficultyName] = ress.errorQuestions;
                });

                this.setData({
                    questionDifficultyAnalyse: list,
                    errorQuestions: errorQuestions
                });
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 2000
                });
            }
        } else {
            wx.redirectTo({
                url: '/pages/newstudentlogin/newstudentlogin',
            });
        }
    },

    async getStuCard() {
        let that = this
        if (wx.getStorageSync('studentToken')) {
            // let stuId = JSON.parse(wx.getStorageSync('studentToken')).id
            // let id = JSON.parse(wx.getStorageSync('examinationInfo')).navId
            let options = {
                url: '/analysis/score/getStuCard',
                method: 'GET',
                data: {
                    examId: this.data.examinationInfo.id,
                    subjectId: this.data.selectMenu.examSubjectId,
                },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            if (res.data.code == 200) {

            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/newstudentlogin/newstudentlogin',
            })
        }
    },
    scoringTips() {
        this.setData({
            scoring: true
        })
    },
    closeMask() {
        this.setData({
            scoring: false
        })
    },
    lookAnswerSheet() {
        let data = JSON.parse(wx.getStorageSync('studentToken'))
        let examId = null
        let subjectId = null
        if (data) {
            examId = this.data.examinationInfo.id,
                subjectId = this.data.selectMenu.examSubjectId
        }
        wx.navigateTo({
            url: `/pages/answerSheet/answerSheet?examId=${examId}&subjectId=${subjectId}&role=2`,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // let option = JSON.parse(wx.getStorageSync('examinationInfo'))
        // //console.log(option, 'vvvvvvc cccccccccccccccc')
        // this.setData({
        //     examType: option.type3,
        //     modelfftype: option.modelFFType
        // })
        // if (option.modelfftype == 1) {
        //     // 全国3+1+2
        //     this.setData({
        //         grading: [
        //             {
        //                 grading: 'A',
        //                 proportion: '15%',
        //                 ratio: '0-15%',
        //                 interval: '100-86'
        //             },
        //             {
        //                 grading: 'B',
        //                 proportion: '35%',
        //                 ratio: '16%-50%',
        //                 interval: '85-71'
        //             },
        //             {
        //                 grading: 'C',
        //                 proportion: '35%',
        //                 ratio: '51%-85%',
        //                 interval: '70-56'
        //             },
        //             {
        //                 grading: 'D',
        //                 proportion: '13%',
        //                 ratio: '86%-98%',
        //                 interval: '55-41'
        //             },
        //             {
        //                 grading: 'E',
        //                 proportion: '2%',
        //                 ratio: '99%-100%',
        //                 interval: '40-30'
        //             }
        //         ],
        //     })
        // } else if (option.modelfftype == 2) {
        //     // 广东3+1+2
        //     this.setData({
        //         grading: [
        //             {
        //                 grading: 'A',
        //                 proportion: '17%',
        //                 ratio: '0-17%',
        //                 interval: '100-83'
        //             },
        //             {
        //                 grading: 'B',
        //                 proportion: '33%',
        //                 ratio: '17%-50%',
        //                 interval: '82-71'
        //             },
        //             {
        //                 grading: 'C',
        //                 proportion: '33%',
        //                 ratio: '50%-83%',
        //                 interval: '70-59'
        //             },
        //             {
        //                 grading: 'D',
        //                 proportion: '15%',
        //                 ratio: '83%-98%',
        //                 interval: '58-41'
        //             },
        //             {
        //                 grading: 'E',
        //                 proportion: '2%',
        //                 ratio: '99%-100%',
        //                 interval: '40-30'
        //             }
        //         ],
        //     })
        // } else if (option.modelfftype == 3) {
        //     // 山东3+3
        //     this.setData({
        //         grading: [
        //             {
        //                 grading: 'A',
        //                 proportion: '3%',
        //                 ratio: '0-3%',
        //                 interval: '100-91'
        //             },
        //             {
        //                 grading: 'B+',
        //                 proportion: '7%',
        //                 ratio: '3%-10%',
        //                 interval: '90-81'
        //             },
        //             {
        //                 grading: 'B',
        //                 proportion: '16%',
        //                 ratio: '10%-26%',
        //                 interval: '80-71'
        //             },
        //             {
        //                 grading: 'C+',
        //                 proportion: '24%',
        //                 ratio: '26%-50%',
        //                 interval: '70-61'
        //             },
        //             {
        //                 grading: 'C',
        //                 proportion: '24%',
        //                 ratio: '50%-74%',
        //                 interval: '60-51'
        //             },
        //             {
        //                 grading: 'D+',
        //                 proportion: '16%',
        //                 ratio: '74%-90%',
        //                 interval: '50-41'
        //             },
        //             {
        //                 grading: 'D',
        //                 proportion: '7%',
        //                 ratio: '90%-97%',
        //                 interval: '40-31'
        //             },
        //             {
        //                 grading: 'E',
        //                 proportion: '3%',
        //                 ratio: '97%-100%',
        //                 interval: '30-21'
        //             },
        //         ],
        //     })
        // }
        // this.getMenuLists()
        // this.getToken()
        let examinationInfo = JSON.parse(wx.getStorageSync('examinationInfo'))
        this.setData({
            examinationInfo: examinationInfo
        })
        console.log(examinationInfo, 'oooooooooooooooooooooooooooo');
        this.getScoreInfo()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let query = wx.createSelectorQuery()
        query.select('#myElementss').boundingClientRect((rect) => {
            //console.log(rect, 'aaaaaaaaaaaaaaaaaaaaaaa');
            this.setData({
                height: rect.top + 10 + 'px'
            })

        }).exec()
        // this.ecDataTrendComponents = this.selectComponent('#mychart-dom-radar');
        // this.getTrends()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
        wx.removeStorageSync('selectMenu')
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        wx.removeStorageSync('selectMenu')
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})